home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-02-09 | 4.6 KB | 167 lines | [TEXT/PJMM] |
- { THIS CODE REQUIRES Think Pascal v2.0 OR ABOVE TO COMPILE USING THE MULTISEGMENT }
- { AND DRIVER OPTIONS }
- { Source for a driver that is used as a Control Manager CDEF }
- { This CDEF will simulate the standard controls: Button, Checkbox, and Radio button }
- { using Object Pascal. }
- { It must be called and maintained by a code resource shell that is in turn }
- { called and maintained by the Control Manager }
- { The driver routines will be called by the CDEF given messages passed to it }
- { These messages are translated as follows: }
- { CDEF message Driver routine }
- { initCntl Open Required for Think to set up }
- { dispCntl Close Required for Think to close down }
- { all others Control Pass message in CodeToDriver^^.fMessage }
-
- unit BasicCDEFDriver;
-
- interface
-
- uses
- ControlObjUnit;
-
- function Main (theDCE: DCtlPtr; IOPB: ParmBlkPtr; sel: Integer): OSErr;
-
- implementation
-
- const
- {Define all of the possible driver calls}
- DriverOpen = 0;
- DriverPrime = 1;
- DriverControl = 2;
- DriverStatus = 3;
- DriverClose = 4;
-
- type
- { CodeToDriver passes parameters from the code resource into driver }
- { add or change any parameters that apply to your code resource }
- CodeToDriver = record
- fMessage: integer; { message }
- fVarCode: integer; { VarCode }
- fControl: ControlHandle; { theControl }
- fParam: LongInt; { Param }
- fResult: LongInt; { result to return to Control Manager }
- end;
- CtoDPtr = ^CodeToDriver;
- CtoDHdl = ^CtoDPtr;
-
- var
- { Think Pascal initializes all globals to 0 before the Open message is called }
- gOpenFlag: integer; { when 0, we haven't initialized }
-
- { globals and objects }
- gButton: tControlObj;
-
- {------------------------------------------------------}
-
- function Main (theDCE: DCtlPtr; IOPB: ParmBlkPtr; sel: Integer): OSErr;
-
- {********************************************}
-
- function OpenRtn: OSErr;
- { create and initialize the object given the varcode }
- var
- theCtoDHdl: CtoDHdl;
- begin
- OpenRtn := noErr; { init }
-
- if gOpenFlag = 0 then {DA not already opened}
- begin
- theCtoDHdl := CtoDHdl(theDCE^.dCtlPosition);
-
- { create and initialize the main object based on VarCode }
- gButton := nil;
- case theCtoDHdl^^.fVarCode of
- pushButProc: { simple button }
- New(tPushButObj(gButton));
- checkBoxProc: { check box }
- New(tCheckBoxObj(gButton));
- radioButProc: { radio button }
- New(tRadioButObj(gButton));
- otherwise
- end; { case theCtoDHdl^^.fVarCode }
-
- if gButton <> nil then
- begin
- gButton.mInit(theCtoDHdl^^.fControl); { call the initialize routine }
- gOpenFlag := 1; { indicates we're OK for Control calls }
- end
- else
- OpenRtn := -1; { error! }
- end;
- end; { OpenRtn }
-
- {********************************************}
-
- function CloseRtn: OSErr;
- { Free the object }
-
- begin { Close }
- CloseRtn := noErr; { init }
- if gOpenFlag <> 0 then
- begin
- gButton.mFree;
- end;
- end; { CloseRtn }
-
- {********************************************}
-
- function ControlRtn: OSErr;
- { processes a code resource message }
- const
- calcCntlRgn = 10;
- var
- theCtoDHdl: CtoDHdl;
- begin
- theCtoDHdl := CtoDHdl(theDCE^.dCtlPosition);
-
- with theCtoDHdl^^ do { theCtoDHdl is locked by caller }
- case fMessage of
- drawCntl:
- gButton.mDraw(fParam); { fParam contains the part code }
- testCntl:
- fResult := gButton.mTest(fParam); { fParam is a mouse point }
- calcCRgns, calcCntlRgn:
- gButton.mCalcRgn(fParam, fMessage); { fParam is a region handle }
- posCntl:
- gButton.mPosition(fParam); { fParam is position offset }
- thumbCntl:
- gButton.mCalcThumb(fParam); { fParam is a pointer to a record }
- dragCntl:
- fResult := gButton.mDrag(fParam); { fParam indicates the type of drag }
- autoTrack:
- gButton.mAutoTrack(fParam); { fParam contains the part code }
- otherwise
- end; { case fMessage }
-
- end; { ControlRtn }
-
- {********************************************}
-
- begin
- { Think Pascal allocates dCtlStorate to its A4 world on as it }
- { processes the Open message. If it cannot be allocated, test here and fail }
- if theDCE^.dCtlStorage = nil then { A4 word isn't there }
- begin
- SysBeep(1); {*** need an alert here ***}
- Main := -1;
- Exit(Main);
- end;
-
- case sel of
- DriverOpen:
- Main := OpenRtn;
- DriverPrime:
- Main := noErr;
- DriverControl:
- if gOpenFlag <> 0 then
- main := ControlRtn;
- DriverStatus:
- Main := noErr;
- DriverClose:
- Main := CloseRtn;
- end;
- end; { Main }
-
- {------------------------------------------------------}
-
- end. { unit BasicCDEFDriver }